﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Text;
using System.Threading.Tasks;
using Test.EventBus2.Core;
using Test.EventBus2.Message.Events.Orders;

namespace Test.EventBus2.Order.Handlers
{
    public class OrderHandler : IHandleMessages<OrderCreationEvent>, IHandleMessages<PayemntedEvent>
    {
        IBus _bus;
        public OrderHandler(IBus bus)
        {
            _bus = bus;
        }
        public Task Handle(OrderCreationEvent message)
        {
            Console.WriteLine("收到订单创建" + message.ProductName);
            //发送支付信息到payment mircoservice
            _bus.PublishMessage(
                new PayemntEvent
                {
                    OrderId = Guid.NewGuid(),
                    PayMethod = "支付宝支付",
                    requestID = 10,
                    TotalPrice = 129.8m
                }
            );
            return Task.CompletedTask;
        }

        public Task Handle(PayemntedEvent message)
        {
            Console.WriteLine("已完成支付" + message.PayMethod + "||" + message.TotalPrice);
            return Task.CompletedTask;

        }
    }

}
